﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Collections.Specialized;
using System.Collections;
using System.Runtime.InteropServices;

namespace TestEffectiveCS
{
    class Test40
    {
        class MyClass
        {

        }
        [Serializable]
        [ComVisible(true)]
        abstract class MyCollectionBase : IList
        {
            protected MyCollectionBase()
            {
                Console.WriteLine("Construct MyCollectionBase");
            }

            ArrayList list = new ArrayList();
            protected ArrayList InnerList { get { return list; } }
            protected IList List { get { return list; } }

            //public int Add(object value)
            //{
            //    return list.Add(value);
            //}

            #region IList 成员

            int IList.Add(object value)
            {
                Console.WriteLine("IList add value");
                return list.Add(value);
            }

            void IList.Clear()
            {
                throw new NotImplementedException();
            }

            bool IList.Contains(object value)
            {
                throw new NotImplementedException();
            }

            int IList.IndexOf(object value)
            {
                throw new NotImplementedException();
            }

            void IList.Insert(int index, object value)
            {
                throw new NotImplementedException();
            }

            bool IList.IsFixedSize
            {
                get { throw new NotImplementedException(); }
            }

            bool IList.IsReadOnly
            {
                get { throw new NotImplementedException(); }
            }

            void IList.Remove(object value)
            {
                throw new NotImplementedException();
            }

            void IList.RemoveAt(int index)
            {
                throw new NotImplementedException();
            }

            object IList.this[int index]
            {
                get
                {
                    throw new NotImplementedException();
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            #endregion

            #region ICollection 成员

            void ICollection.CopyTo(Array array, int index)
            {
                throw new NotImplementedException();
            }

            int ICollection.Count
            {
                get { throw new NotImplementedException(); }
            }

            bool ICollection.IsSynchronized
            {
                get { throw new NotImplementedException(); }
            }

            object ICollection.SyncRoot
            {
                get { throw new NotImplementedException(); }
            }

            #endregion

            #region IEnumerable 成员

            IEnumerator IEnumerable.GetEnumerator()
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        class MyCollection : MyCollectionBase
        {
            public int Add(MyClass myClass)
            {
                Console.WriteLine("MyCollection add myClass");
                return List.Add(myClass);
            }
        }


        class Collection : CollectionBase
        {
            public void Add(MyClass myClass)
            {
                List.Add(myClass);
            }

            public void Remove(MyClass myClass)
            {
                List.Remove(myClass);
            }

            public MyClass this[int index]
            {
                get { return (MyClass)List[index]; }
                set { List[index] = value; }
            }
        }

        class MyDictionary : DictionaryBase
        {
            public void Add(int key, string value)
            {
                Dictionary.Add(key, value);
            }
            public void Remove(int key)
            {
                Dictionary.Remove(key);
            }
            public string this[int key]
            {
                get { return (string)Dictionary[key]; }
                set { Dictionary[key] = value; }
            }
        }


        public Test40()
        {
            ListDictionary LD = new ListDictionary();
            LD.Add("Key", "Value");
            HybridDictionary HD = new HybridDictionary();
            HD.Add("Key", "Value");
            Hashtable HT = new Hashtable();
            HT.Add("Key", "Value");
            SortedList SL = new SortedList();
            SL.Add("Key", "Value");
            Array A = new int[100];
            ArrayList AL = new ArrayList();
            AL.Add("Key");
            BitArray BA = new BitArray(new bool[0]);

            Collection CB = new Collection();
            MyClass MC = new MyClass();
            CB.Add(MC);
            IList list = CB;
            list.Add(MC);

            MyCollection MCT = new MyCollection();
            MCT.Add(MC);
            IList ilist = MCT;
            ilist.Add(MC);
        }
    }
}
